package com.thon.controller.rest;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.hibernate.HibernateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.thon.dao.util.Page;
import com.thon.entity.project.Project;
import com.thon.entity.project.ProjectCategory;
import com.thon.entity.project.Region;
import com.thon.entity.system.Configure;
import com.thon.entity.user.Charitarian;
import com.thon.entity.user.Coupon;
import com.thon.entity.user.FinanceView;
import com.thon.entity.user.FundDetail;
import com.thon.entity.user.Institution;
import com.thon.entity.user.User;
import com.thon.service.project.ProjectCategoryService;
import com.thon.service.project.ProjectService;
import com.thon.service.project.RegionService;
import com.thon.service.system.ConfigureService;
import com.thon.service.user.CharitarianService;
import com.thon.service.user.CouponService;
import com.thon.service.user.FundDetailService;
import com.thon.service.user.InstitutionService;
import com.thon.service.user.UserService;


@Controller
@RequestMapping("/api/configure")
@SuppressWarnings({ "rawtypes", "unchecked" })
public class ConfigureRestController {
	@Autowired
	private ConfigureService configService;


	// 根据用获取基本配置
	@RequestMapping(value = "/get", method = RequestMethod.GET)
	public ResponseEntity<HttpEntity> getConfigureInfo() {

		Configure configure = configService.get();

		return new ResponseEntity(configure, HttpStatus.CREATED);
	}
	
	// 根据用户角色分页获取用户列表
		@RequestMapping(value = "/get/{by}", method = RequestMethod.GET)
		public ResponseEntity<HttpEntity> getSomeInfo(@PathVariable("by")String by){	
			
			return new ResponseEntity(configService.get(by), HttpStatus.CREATED);
		}
		
	
	//根据用户id修改用户角色
	@RequestMapping(value = "/update", method = {RequestMethod.GET,RequestMethod.POST})
	public ResponseEntity<?> updateUserRole(Configure configure){		
		configService.update(configure);
		return new ResponseEntity(true, HttpStatus.OK);
	}	
	
	//返回联系人信息
	@RequestMapping(value = "/getRelation", method = {RequestMethod.GET})
	public ResponseEntity<?> getRelation(HttpServletRequest request,Model model){		
		
		model.addAttribute("phone", configService.get("phone"));
		model.addAttribute("address", configService.get("address"));
		model.addAttribute("username", configService.get("username"));
		model.addAttribute("qq", configService.get("qq"));
		model.addAttribute("mail", configService.get("mail"));
		
		return new ResponseEntity(model, HttpStatus.OK);
	}	
	
}
